<template>
  <div class="app-container task">
    <el-dialog
      title="选择养护任务"
      :visible.sync="dialogTableVisible"
      :close-on-click-modal="false"
      :before-close="close"
      width="900px"> 
      <el-form :model="selectForm" ref="queryForm" :inline="true">
        <el-form-item label="任务单号：">
          <el-input size="small"  v-model="selectForm.taskCoder" placeholder="请输入任务单号" clearable/>
        </el-form-item>
        <el-form-item label="计划名称：">
          <el-input size="small"  v-model="selectForm.planName" placeholder="请输入计划名称" clearable/>
        </el-form-item>
        <el-form-item>
          <el-button size="mini" type="primary" icon="el-icon-search" @click="selectForm.pageNum=1;getList();">搜索</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="loading" :data="list" stripe border  >
        <el-table-column align="center" type="index" label="序号" width="55"/>
        <el-table-column align="center" label="计划单号" prop="planCoder"/>
        <el-table-column align="center" label="计划名称" prop="planName"/>
        <el-table-column align="center" label="任务单号" prop="taskCoder"/>
        <el-table-column label="截止日期" align="center" prop="endDate" >
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.endDate) }}</span>
          </template>
        </el-table-column>
        <el-table-column align="center" label="任务状态" prop="maintainType">
          <template slot-scope="scope">
            <el-button size="mini" v-if="scope.row.taskStatus==1" type="warning">未执行</el-button>
            <el-button size="mini" v-if="scope.row.taskStatus==2" type="danger">已完成</el-button>
            <el-button size="mini" v-if="scope.row.taskStatus==3" type="success">已作废</el-button>
          </template>
        </el-table-column>
        <el-table-column align="center" label="是否选用">
          <template slot-scope="scope">
            <el-button type="primary" size="mini" @click="sumbit(scope.row)">
              选用
            </el-button>
          </template>
        </el-table-column>

      </el-table>
      <pagination
        :total="total"
        :page.sync="selectForm.pageNum"
        :limit.sync="selectForm.pageSize"
        @pagination="getList"
        :page-sizes="[5,10,30, 50]"
      />
      <span slot="footer" class="dialog-footer">
      <el-button size="mini" @click="sumbit">确定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
  import {getConserveTaskList} from '@/api/curing/index' 
  export default {
    name: "task.vue",
    props:['info'],
    data() {
      return {
        dialogTableVisible: true,
        loading: false,//加载
        selectForm: {
          planId:null,
          planName: null,
          taskCoder: null,//备件编号
          pageNum: 1,
          pageSize: 5,
        },//查询条件
        list: [],//数据
        total: 0,
      }
    },
    created() {
      this.getList()
    },
    methods: {
      getList(){
        if(this.info){this.selectForm.planId=this.info.id}
        getConserveTaskList(this.selectForm).then((res)=>{
          if(res.code==200){
            this.list=res.rows
            this.total=res.total
          }
        })
      },
      close() {
        this.$emit('taskChange')
      },
      sumbit(row) {
        console.log(row);
        this.$emit('taskChange', row)
      },
    }
  }
</script>

<style lang="scss">
  .task{
    .option{
      width: 200px;
      height:32px;
      .vue-treeselect__control{
        line-height: 32px;
        height:32px !important;
      }
    }
  }
</style>

